//
//  HSettingWC.m
//  HMusicPlayer
//
//  Created by hament deng on 14/10/23.
//  Copyright (c) 2014年 HJ. All rights reserved.
//

#import "HSettingWC.h"
#import "HMainWC.h"
#import "HCoreConfig.h"
#import "HLrcView.h"

@interface HSettingWC ()

@property (nonatomic)NSUInteger count;

@end

@implementation HSettingWC

- (void)windowDidLoad {
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    
    NSColor * ncolor=[NSColor grayColor];
    NSColor * hcolor=[NSColor whiteColor];
    
    
    //设置可选字体
    [self.lyricFullPopup removeAllItems];
    
    [self.lyricFullPopup addItemsWithTitles:@[@"24",@"26",@"28",@"30",@"32",@"34",@"36",@"38",@"40",@"42",@"44",@"46",@"48",@"50",@"52",@"54",@"56",@"58",@"60",@"70",@"76",@"82"]];
    
    NSString * fontSize=[NSString stringWithFormat:@"%lu",(unsigned long)[HCoreConfig shareConfig].lyricsFullScreenFontSize];
    [self.lyricFullPopup setTitle:fontSize];
    
    
    
    //翻译
    [HCoreConfig configButton:self.askDeleteItunesBtn Title:NSLocalizedString(@"Ask me when delete itunes music", nil) normalColor:ncolor helightedColor:hcolor shadow:nil];
    [HCoreConfig configButton:self.askAutoDownloadLyrics Title:NSLocalizedString(@"Auto download lyrics", nil) normalColor:ncolor helightedColor:hcolor shadow:nil];
    
    self.fullScreenLyricLab.stringValue=NSLocalizedString(@"Lyrics font size in full screen mode", nil);
    self.window.title=NSLocalizedString(@"Setting", nil);
    
    [self.saveBtn setTitle:NSLocalizedString(@"Close", nil)];
    
    if ([HCoreConfig shareConfig].autoDownloadLyrics) {
        self.askAutoDownloadLyrics.state=NSOnState;
    } else {
        self.askAutoDownloadLyrics.state=NSOffState;
    }
    
    
    if ([HCoreConfig shareConfig].removeItunesAsk) {
        self.askDeleteItunesBtn.state=NSOnState;
    } else {
        self.askDeleteItunesBtn.state=NSOffState;
    }

  
}




- (IBAction)selectFullLyricsFontSize:(NSPopUpButton *)sender {
    
    
    NSMenuItem * selectItem=  [sender selectedItem];
    [sender setTitle:selectItem.title];
    
    [HCoreConfig shareConfig].lyricsFullScreenFontSize=selectItem.title.integerValue;
    
    [[HMainWC shareWc].lyricView reloadlyricStyleAndData];
    
    
}

- (IBAction)save:(NSButton *)sender {

    [self.window close];
   
   
}

#pragma mark 删除询问
- (IBAction)toggleAskDeleteItunes:(NSButton *)sender {
    
    if (sender.state==NSOnState) {
        [HCoreConfig shareConfig].removeItunesAsk=YES;
    } else {
        [HCoreConfig shareConfig].removeItunesAsk=NO;
    }
}


#pragma mark 自动下载歌词
- (IBAction)toggleAutoDownloadLyrics:(NSButton *)sender {
    
    if (sender.state==NSOnState) {
        [HCoreConfig shareConfig].autoDownloadLyrics=YES;
    } else {
        [HCoreConfig shareConfig].autoDownloadLyrics=NO;
    }
    
    
    
}


#pragma mark window delegate
-(void)windowWillClose:(NSNotification *)notification {
    
    if ([[HCoreConfig shareConfig].holdWindoControllerArr containsObject:self]) {
        [[HCoreConfig shareConfig].holdWindoControllerArr removeObject:self];
    }
    
}

@end
